package com.bjb.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.bjb.config.UeditorUploadConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baidu.ueditor.ActionEnter;

@EnableAutoConfiguration
@RestController
@RequestMapping("/ueditor")
public class UeditorController {

    @Autowired
    private UeditorUploadConfig ueditorUploadConfig;

    @RequestMapping(value = "/controller")
    public void controller(HttpServletRequest request, HttpServletResponse response) throws IOException {
        request.setCharacterEncoding("utf-8");
        response.setHeader("Content-Type", "text/html");
        String rootPath = request.getSession().getServletContext().getRealPath("/");
        PrintWriter out = response.getWriter();
        String str = new ActionEnter(request, rootPath, ueditorUploadConfig).exec();
        out.write(str);
    }
}
